package com.kfm.servlet;

import com.kfm.util.Contains;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@WebServlet("/online")
public class OnlineServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        ServletContext servletContext = getServletContext();

        Object attribute = servletContext.getAttribute(Contains.ONLINE_ACCOUNT);

        if (attribute instanceof Map map){
            req.setAttribute("count", map.size());
            req.setAttribute("accounts", map);
            req.getRequestDispatcher("WEB-INF/online.jsp").forward(req, resp);
        }


    }
}
